package ua.kpi_java_training.evgeniygusar.module3;

public class DesertInAction {
    public AllLeopards leopardsObject = new AllLeopards();
    public int current_step=0;
    public AllOstriches ostrichesObject = new AllOstriches();

    public int total_number_of_borning_ostriches = 1;
    public int total_number_of_borning_leopards = 1;

    /**
     * Function for starting living in desert
     * @param current_step - current step of all inhabitants of desert
     */

    public void startAction(int current_step){
        this.current_step = current_step;
        displayNextStep(current_step);

        if (ostrichesObject.numbersOfOstriches() != 0) {
            ostrichesObject.ostrichesMoving();
            ostrichesObject.displayOstrichesMoving();
            leopardsObject.leopardsMoving();
        }

        checkOstrichBorning();
        checkLeopardBorning();
    }

    /**
     *  Function for displaing current step of all inhabitants of desert
     * @param current_step - current step of them
     */

    void displayNextStep(int current_step) {
        System.out.println("-----------------------------");
        System.out.println("Step " + current_step);
    }

    /**
     * Function that check if it's time to born new ostrich
     */

    void checkOstrichBorning() {
        if (current_step%ostrichesObject.getOstrichBirthCycle()==0) {
            ostrichesObject.addOstrich();
            total_number_of_borning_ostriches++;
            System.out.println("New ostrich is borning!");
            System.out.print("Ostrich " + (ostrichesObject.numbersOfOstriches()) + ": ");
            ostrichesObject.getOstrich(ostrichesObject.numbersOfOstriches() - 1).showCoordinats();
        }
    }

    /**
     * Function that check if it's time to born new leopard
     */

    void checkLeopardBorning() {
        if (current_step%leopardsObject.getLeopardBirthCycle()==0) {
            leopardsObject.addLeopard();
            total_number_of_borning_leopards++;
            System.out.println("New leopard is borning!");
            System.out.print("Leopard " + (leopardsObject.numbersOfLeopards()) + ": ");
            leopardsObject.getLeopard(leopardsObject.numbersOfLeopards() - 1).showCoordinats();
        }
    }

    /**
     * Function for output of all statistics of living in desert
     */

    void showStatistics() {
        System.out.println("-----------------------------");
        System.out.println("Total number of borning ostriches: " + total_number_of_borning_ostriches);
        System.out.println("Total number of eated ostriches by leopards: " + leopardsObject.getTotalNumberOfEatedOstriches());
        System.out.println("Number ostriches that still living: " + ostrichesObject.numbersOfOstriches());
        System.out.println("Total number of borning leopards: " + total_number_of_borning_leopards);
    }
}

